package cn.net.cfss.fgbp.face.console.controller;

import cn.net.cfss.fgbp.api.console.inte.ISysRoleMenuService;
import cn.net.cfss.fgbp.api.console.vo.SysRoleMenuVo;
import cn.net.cfss.fgbp.base.constant.ErrCodeEnum;
import cn.net.cfss.fgbp.base.controller.BaseController;
import cn.net.cfss.fgbp.face.console.util.ReturnUtil;
import cn.net.cfss.fgbp.face.console.vo.BaseParas;
import cn.net.cfss.fgbp.log.influxdb.ApiDto;
import cn.net.cfss.fgbp.log.statistics.IStatsdLogService;
import cn.net.cfss.fgbp.log.statistics.LogDtoFactory;
import cn.net.cfss.fgbp.log.util.LogStandardUtil;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.UUID;

/**
 * @author oygq
 * @title: SysRoleMenuController
 * @description: TODO
 * @date 2019/4/8 14:13
 */
@RestController
@Slf4j
@RequestMapping("console/roleMenu")
public class SysRoleMenuController extends BaseController {

    @Autowired
    ISysRoleMenuService sysRoleMenuService;

    @ApiOperation("角色菜单新增")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String inset(@RequestBody BaseParas paras){
        SysRoleMenuVo vo = JSONObject.toJavaObject(paras.getPlain(),SysRoleMenuVo.class);
        if(sysRoleMenuService.insert(vo)){
            return ReturnUtil.returnSucc();
        }
        return ReturnUtil.returnErr(ErrCodeEnum.ERR);
    }

    @ApiOperation("角色菜单修改")
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public String update(@RequestBody BaseParas paras){
        SysRoleMenuVo vo = JSONObject.toJavaObject(paras.getPlain(),SysRoleMenuVo.class);
        if(sysRoleMenuService.update(vo)){
            return ReturnUtil.returnSucc();
        }
        return ReturnUtil.returnErr(ErrCodeEnum.ERR);
    }

    @ApiOperation("角色菜单删除")
    @RequestMapping(value = "/delete/{roleMenuId}", method = RequestMethod.POST)
    public String update(@PathVariable Long roleMenuId){
        if(null == roleMenuId){
            return ReturnUtil.returnErr("角色按钮为空");
        }
        if(sysRoleMenuService.delete(roleMenuId)){
            return ReturnUtil.returnSucc();
        }
        return ReturnUtil.returnErr(ErrCodeEnum.ERR);
    }

    @ApiOperation("角色菜单批量删除")
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    public String deleteBatch(@RequestBody BaseParas paras){
        List<Long> roleMenuIds = (List<Long>) paras.getPlain().get("roleMenuIds");
        if(sysRoleMenuService.deleteBatch(roleMenuIds.toArray(new Long[roleMenuIds.size()]))){
            return ReturnUtil.returnSucc();
        }
        return ReturnUtil.returnErr(ErrCodeEnum.ERR);
    }

    @ApiOperation("根据角色id查询菜单")
    @RequestMapping(value = "/query/{roleId}", method = RequestMethod.POST)
    public String queryByList(@PathVariable Long roleId){
        List<Long> menus = sysRoleMenuService.queryByRoleId(roleId);
        return ReturnUtil.returnSucc(menus);
    }

    @ApiOperation("角色菜单删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public String deleteByMenus(@RequestBody BaseParas paras){
        SysRoleMenuVo vo = JSONObject.toJavaObject(paras.getPlain(),SysRoleMenuVo.class);
        if(sysRoleMenuService.deleteByMenus(vo)){
            return ReturnUtil.returnSucc();
        }
        return ReturnUtil.returnErr(ErrCodeEnum.ERR);
    }

}

